// <editor-fold defaultstate="collapsed" desc="GNU GPLv3 Header">
/*
 * File:   Main.java
 *
 * Copyright (C) 2013 Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * Copyright (C) 2013 David Megias Jimenez <dmegias@uoc.edu>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// </editor-fold>
package compressiontest2;

// <editor-fold defaultstate="collapsed" desc="imports">
import uoc.libcompression.G711.AlawEncoder;
import uoc.libcompression.G711.AlawDecoder;
import uoc.libcompression.G711.UlawDecoder;
import uoc.libcompression.G711.UlawEncoder;
// </editor-fold>

/**
 *
 * @author Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * @version 1.0
 * @since 2013-08-09
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // s:0000:000w:xyza
        short sample = (short) -5;

        System.out.println("A-Law test");
        System.out.println("Original   : " + sample + " = "
                + Integer.toBinaryString(sample & 0x1FFF));
        AlawEncoder alawEncoder = new AlawEncoder();
        byte compressed = alawEncoder.compress(sample);
        System.out.println("Compressed : " + compressed + " = "
                + Integer.toBinaryString(compressed & 0xFF));
        AlawDecoder alawDecoder = new AlawDecoder();
        short expanded = alawDecoder.expand(compressed);
        System.out.println("Expanded   : " + expanded + " = "
                + Integer.toBinaryString(expanded & 0x1FFF));

        System.out.println();

        System.out.println("A-Law test (Transmission)");
        System.out.println("Original   : " + sample + " = "
                + Integer.toBinaryString(sample & 0x1FFF));
        compressed = alawEncoder.compressTransmission(sample);
        System.out.println("Compressed : " + compressed + " = "
                + Integer.toBinaryString(compressed & 0xFF));
        expanded = alawDecoder.expandTransmission(compressed);
        System.out.println("Expanded   : " + expanded + " = "
                + Integer.toBinaryString(expanded & 0x1FFF));


        System.out.println();


        // s0:0000:000w:xyza
        sample = 0x1FFF;
        System.out.println("U-Law test");
        System.out.println("Original   : " + sample + " = "
                + Integer.toBinaryString(sample & 0x3FFF));

        UlawEncoder ulawEncoder = new UlawEncoder();
        compressed = ulawEncoder.compress(sample);
        System.out.println("Compressed : " + compressed + " = "
                + Integer.toBinaryString(compressed & 0xFF));

        UlawDecoder ulawDecoder = new UlawDecoder();
        expanded = ulawDecoder.expand(compressed);
        System.out.println("Expanded   : " + expanded + " = "
                + Integer.toBinaryString(expanded & 0x3FFF));

        System.out.println();

        System.out.println("U-Law test (Transmission)");
        compressed = ulawEncoder.compressTransmission(sample);
        System.out.println("Compressed : " + compressed + " = "
                + Integer.toBinaryString(compressed & 0xFF));
        expanded = ulawDecoder.expandTransmission(compressed);
        System.out.println("Expanded   : " + expanded + " = "
                + Integer.toBinaryString(expanded & 0x3FFF));
    }
}
